package com.walle.concurrenttest.pattern.guardedsuspension;

import java.util.Random;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.guardedsuspension
 * @Description: ${todo}
 * @date 2019/2/18 15:23
 */
public class ClientThread implements Runnable{

    private RequestQueue queue;

    private Random random;

    public ClientThread(RequestQueue queue,long seed) {
        this.queue = queue;
        this.random = new Random(seed);
    }


    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            Request request = new Request("No."+i+" request");
            System.out.println("客户端发送请求：No." + i);
            queue.putRequest(request);
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
